from django.conf import settings
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer

class SecretOauth(object):
    def __init__(self):
        self.serializer = Serializer(serializer_key=settings.SECRET_KEY,expires_in=24*14*3600)
    #1加密
    def dumps(self,data):

        result = self.serializer.dump(data)
        return result.decode()

    #2解密
    def loads(self, data):
        result = self.serializer.loads(data)
        return



# if __name__ == '__main__':
#     s = Serializer(secret_key="abc",expires_in=3600)
#
#     data_dict = {
#         'a':1
#     }
#
#     result = s.dumps(data_dict)
#     print(result)
#
#     loads_result = s.loads(result)
#     print(loads_result)
#     print(type(loads_result))